/**
 * @file categories/heap/opposite_heap/luogu1081
 * @brief 对顶堆是一种动态维护单调区间第k大数或第k小数的数据结构
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/12 11:34:04
 **/

#include <bits/stdc++.h>
using namespace std;
const int N = 500000 + 10;
int a[N], u[N];
priority_queue<int, vector<int>, greater<>> down;  // 小根堆
priority_queue<int, vector<int>, less<>> up;       // 大根堆
int main() {
  // High rating and good luck!
  int m, n;
  cin >> m >> n;
  for (int i = 1; i <= m; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> u[i];

  int now = 0;  // 执行到了 a[now]
  for (int i = 1; i <= n; ++i) {
    while (now < u[i]) {
      now++;
      // 从大根堆推到小根堆
      up.push(a[now]);
      down.push(up.top());
      up.pop();
    }
    // 从小根堆推到大根堆
    printf("%d\n", down.top());
    up.push(down.top());
    down.pop();
  }
  return 0;
}
